<?php

namespace Home\Controller;

use Think\Controller;

class H5apiController extends Controller
{
    /*
     * 平台服务Api
     */

    //获取接口地址
    private function getBaseUrl()
    {
       // return "http://112.33.1.160:81/healthcare_service_restful/";            //本地服务器
         return "http://service.health.10086.cn:8083/healthcare_service_restful/";     //线上服务器
   }

   private function getOperationsBaseUrl(){
        // return "http://112.33.1.160:81/healthcare_operations_restful/";     //本地开发
        return "http://health.10086.cn/healthcare_operations_restful/";     //正式服


    }

    private function appKey()
    {
        return 'ZSTJ';
    }

    private function invokeKey()
    {
//        return '[ZSTJ-S]240sgSOKlC';
        return '[ZSTJ-P]Q0hitfewWu';        //获取商城套餐列表
    }

    //体检套餐分类页面
    public function packageClassify(){
        $uid=htmlspecialchars($_GET['uid']);
        $this->assign("uid",$uid);
        $this->display();
    }

    //套餐商品列表
    public function packageList()
    {
        //打点统计
        dadian("套餐商品列表");

        //生成缓存
        $cachePackageList=S("cachePackageList","",array("prefix"=>"packageList_","temp"=>RUNTIME_PATH.'Temp/store'));
        // dump($cachePackageList);exit();
        // S('cachePackageList',NULL); // 清除缓存


        if(!$cachePackageList){
            $url = $this->getBaseUrl() . "s/infoPhysicalExamination/getInfoPhysicalExaminationList";
            $data = array(
                'appKey' => $this->appKey(),
                'invokeKey' => $this->invokeKey(),
                'status' => 0,
                'pageSize' => 1000,
                );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            $return = curl_exec($ch);
            curl_close($ch);

            $getinfo = get_object_vars(json_decode($return));
            $result = get_object_vars(json_decode($getinfo['jsonResult']));
            $dataList = (array)$result['dataList'];

            function mb_strs($str = '', $offset = 0, $len = 0){
                $len || ($len = strlen($str));
                preg_match_all('/./us', $str, $result);
                return implode('', array_slice($result[0], $offset, $len));
            }

            foreach ($dataList as $key => $value) {
                    $val = $value->name;
                    $va = mb_strs( $val, 0, 2);
                    if($va=='通用'  || $va=='美兆' || $va=='政企'){
                        unset($dataList[$key]);
                    }

            }

            // 生产环境php未开启mb_substr函数
            // foreach ($dataList as $key => $value) {
            //         $val = $value->name;
            //         $va = mb_substr( $val, 0, 4);
            //         if($va=='通用套餐'  || $va=='美兆套餐'){
            //             array_splice($dataList,$key);
            //         }
            // }


        //生成缓存
            $cacheState=S("cachePackageList",$dataList,array("prefix"=>"packageList_","temp"=>RUNTIME_PATH.'Temp/store'));
            // dump($cacheState);
            //获取缓存
            $cachePackageList=S("cachePackageList","",array("prefix"=>"packageList_","temp"=>RUNTIME_PATH.'Temp/store'));
        }
        // dump($cachePackageList);

        $this->assign("dataList", $cachePackageList);
        $this->display("packageList");
    }

    /*
     * 套餐详情页面,包括套餐体检项目、套餐所适用的体检机构
     */
    public function getPackageDetail()
    {
        // echo "hello";exit();
        //获取改套餐的体检项目
        $packageid=$_GET['packageId']?$_GET['packageId']:"";
        $packageid=htmlspecialchars($packageid);
        $url = $this->getBaseUrl() . "s/infoPhysicalExamination/getInfoPhysicalExaminationList";
        $data = array(
            'appKey' => $this->appKey(),
            'invokeKey' => $this->invokeKey(),
            'packageId' => $packageid,
            'status' => 0,
            );


        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $return = curl_exec($ch);
        // var_dump($return);exit();
        curl_close($ch);

        $getinfo = get_object_vars(json_decode($return));
        $result = get_object_vars(json_decode($getinfo['jsonResult']));
        $packageContent = $result['dataList'][0];

        //获取套餐适用的体检机构
        $centerDetail=$this->getInfoPepMcList($_GET['packageId']);
        // var_dump($centerDetail);exit();
        $cacheCenterList=S("cacheCenterList","",array("prefix"=>$packageid,"temp"=>RUNTIME_PATH.'Temp/store'));
        // var_dump($cacheCenterList);exit();
        if(!$cacheCenterList){
            // echo "here";exit();
            $centerList=array();
            $url = "http://localhost" . U("Serviceapi/getMedicalCenterBranchList");
            foreach($centerDetail as $key=>$value){
                $data=array(
                    'appKey' => $this->appKey(),
                    'invokeKey' => $this->invokeKey(),
                    'mcbId' => $value->mcbId,
                    );

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $return = curl_exec($ch);
                // $result  =json_decode($return);
                // var_dump($return);exit();
                curl_close($ch);
                $getinfo = get_object_vars(json_decode($return));
                // var_dump($getinfo);exit();
                $jsonResult=$getinfo['jsonResult'];
                $dataList=json_decode($jsonResult)->dataList[0];
                // var_dump($dataList);exit();
                $var =array(
                    'address'=>$dataList->address,
                    'name'=>$dataList->name,
                    'mcId'=>$dataList->mcId,
                    );
                // var_dump($var);continue;
                array_push($centerList, $var);
            }
            // var_dump($centerList);exit();
            //生成缓存
            $cacheCenterList = S("cacheCenterList",$centerList,array("prefix"=>$packageid,"temp"=>RUNTIME_PATH."Temp/store"));
            //读取缓存
            $cacheCenterList=S("cacheCenterList","",array("prefix"=>$packageid,"temp"=>RUNTIME_PATH.'Temp/store'));
        }
        // var_dump($cacheCenterList);exit();
        $discount = number_format($packageContent->salePrice / $packageContent->originalPrice * 10, 1);
        $this->assign("discount", $discount);
        $this->assign("centerList", $cacheCenterList);
        $this->assign("packageContent", $packageContent);
        $this->display("packageDetail");
    }

    /*
     *  购买确认页面
    */
    public function packageConfirm()
    {
        $url = $this->getBaseUrl() . "s/infoPhysicalExamination/getInfoPhysicalExaminationList";
       // var_dump($url);exit();
        $data = array(
            'appKey' => $this->appKey(),
            'invokeKey' => $this->invokeKey(),
            'packageId' => htmlspecialchars($_GET['packageId']),
           // 'packageId' =>'211002',
            'status' => 0,

            );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $return = curl_exec($ch);
        curl_close($ch);

        $getinfo = get_object_vars(json_decode($return));
        $result = get_object_vars(json_decode($getinfo['jsonResult']));
        $dataList = $result['dataList'][0];
       // var_dump($dataList);exit();
        $favor = $dataList->originalPrice - $dataList->salePrice;       //计算优惠价格
        $this->assign("favor", $favor);
        $this->assign("model", $dataList);
        $this->assign('payinfo', array(
            'action' => __ROOT__ . "/alipaywebmobile/alipayapi.php",
            'account' => 'yjxali@pocdoc.cn',
            ));
       // var_dump($dataList);exit();
        $this->display();
    }


    public function success()
    {
        // var_dump(APP_PATH."../");exit();
        require_once(APP_PATH . "../" . "/alipayweb/alipay.config.php");
        require_once(APP_PATH . "../" . "/alipayweb/lib/alipay_notify.class.php");
        $alipayNotify = new AlipayNotify($alipay_config);

        if (isset($_GET["route"])) {
            unset($_GET["route"]);
        }

        $verify_result = $alipayNotify->verifyReturn();


        if ($verify_result) {
            $out_trade_no = $_GET['out_trade_no'];

            //支付宝交易号

            $trade_no = $_GET['trade_no'];

            //交易状态
            $trade_status = $_GET['trade_status'];


            if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') {
                $purchase = M('Purchase');
                $appointment = M('Appointment');
                $data['pay_status'] = 1;
                $result = $purchase->where('sn=' . $out_trade_no)->save($data);


                $appointment = M('Appointment');
                $getinfo = $purchase->where('sn=' . $out_trade_no)->find();
                for ($i = 0; $i < $getinfo['item_count']; $i++) {
                    $data['uid'] = $getinfo['uid'];
                    $data['item_id'] = $getinfo['item_id'];
                    $data['add_date'] = date('Y-m-d H:i:s', time());
                    $data['appointment_status'] = '1';
                    $appointment->add($data);
                }


                $this->assign('issuccess', '支付成功');
            } else {
                $this->assign('issuccess', '支付失败');
            }
            //——请根据您的业务逻辑来编写程序（以上代码仅作参考）——
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        } else {
            $this->assign('issuccess', '支付失败');
        }

        $this->assign('return', U('Index/meal'));

        $this->display();
    }

    /*
     *体检预约列表界面
     *
     */
    public function appointList()
    {
        $getPost = $_POST;
        $getPost['uid'] = 'kouhuatuo';
        if (isset($getPost['uid'])) {
            $purchase = M('Appointment');
            $results = $purchase->where("uid='" . $getPost['uid'] . "'")->order('add_date desc')->select();
            $returnArray = array();

            // var_dump($results);die();
            foreach ($results as $one) {
                $url = "http://localhost" . U("Serviceapi/getInfoPhysicalExaminationInfo");     //获取体检套餐信息
                $data = array(
                    'packageid' => $one['item_id'],
                    'pageIndex' => '1',
                    'pageSize' => '1'
                    );
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $return = curl_exec($ch);
                curl_close($ch);

                $getinfo = get_object_vars(json_decode($return));

                $itemInfo = $getinfo['dataList'][0];
                //var_dump();exit();

                $data = array(
                    'packageId' => $one['item_id'],
                    'pageIndex' => '1',
                    'pageSize' => '1000'
                    );


                $url = "http://localhost" . U("Serviceapi/getInfoPepMcList");       //获取套餐信息
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $return = curl_exec($ch);
                curl_close($ch);

                $getcenterinfo = get_object_vars(json_decode($return));

                $centerInfo = $getcenterinfo['dataList'][0];


                //  var_dump($centerInfo);
                $mcbid = $centerInfo->mcbId;

                $url = "http://localhost" . U("Serviceapi/getMedicalCenterBranchByMcbid");  //获取体检中心信息

                $data = array(
                    'mcbId' => $one['center_id'],
                    'pageIndex' => '1',
                    'pageSize' => '10000',
                    );

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $return = curl_exec($ch);
                curl_close($ch);

                $branchInfo = get_object_vars(json_decode($return));


                $branchInfo = $branchInfo['dataList'][0];

                $returnArray[] = array(
                    'type' => '1',
                    'status' => $one['appointment_status'],
                    'tid' => $one['id'],
                    'activecode' => 'stractivecode',
                    'packagename' => $itemInfo->name,
                    'packageimg' => $itemInfo->imgSmall,
                    'packagebigimg' => $itemInfo->imgBig,
                    'packagedesc' => $itemInfo->description,
                    'packagecenternum' => $itemInfo->mcbCount,
                    'realname' => $one['u_name'],
                    'identity_no' => $one['u_card'],
                    'telephone' => $one['u_telephone'],
                    'centers' => array(
                        'id' => is_null($branchInfo->mcbId) ? "" : $branchInfo->mcbId,
                        'name' => is_null($branchInfo->address) ? "" : $branchInfo->address,
                        'date' => $one['appointment_date'],
                        ),
                    'packageid' => $one['item_id'],
//                    'centerCount' => $itemInfo->mcbCount,
//                    'centerAddress' => $branchInfo->address,
//                    'centerDate' => 'strcenterDate',
                    );
}
            //die();
echo json_encode(array(
    'status' => '1',
    'data' => $returnArray,
    'msg' => '查询购买成功'
    )
);
} else {
    echo json_encode(array(
        'status' => '0',
        'msg' => '缺失参数'
        )
    );
}
$this->display();
}

    //套餐适用机构
public function getInfoPepMcList($packageId)
{
    $url = $this->getBaseUrl() . "s/infoPepMc/getInfoPepMcList";
    $data = array(
        'appKey' => $this->appKey(),
        'invokeKey' => $this->invokeKey(),
        'packageId' => $packageId,
        'pageSize' => 10000,
        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
        // var_dump($return);exit();
    $getinfo = get_object_vars(json_decode($return));
    $result = get_object_vars(json_decode($getinfo['jsonResult']));
    $centerList = (array)$result['dataList'];
    curl_close($ch);
    return $centerList;


//        //获取套餐详情
//        $url = $this->getBaseUrl() . "s/infoPhysicalExamination/getInfoPhysicalExaminationList";
//        $data = array(
//            'appKey' => $this->appKey(),
//            'invokeKey' =>$this->invokeKey(),
//            'status' => 0,
//
//        );
//        $ch = curl_init();
//        curl_setopt($ch, CURLOPT_URL, $url);
//        curl_setopt($ch, CURLOPT_POST, 1);
//        curl_setopt($ch, CURLOPT_HEADER, 0);
//        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//        $return = curl_exec($ch);
//        curl_close($ch);
//
//        $getinfo = get_object_vars(json_decode($return));
//        $result = get_object_vars(json_decode($getinfo['jsonResult']));
//        $packageList =  (array)$result['dataList'];
//
//
//        //获取体检中心列表
//        $centerList = $this->getMedicalCenterBranchList();
//        return $centerList;


}

/**
 * 推荐的体检中心
 * @param $packageid // 套餐id
 * @param
 * @return array
 *
 */
private function adviceAddressList($packageid)
{
    // $packageid=htmlspecialchars($packageid);
    if(!isset($packageid)) return false;
    $packageid = $packageid;
    $tuijian = M('advice_cbid'); //推荐表
    $adviceMcbid = $tuijian -> field('mcbid') -> where('mcstate=2') -> select(); // 获取推荐的体检中心
    // dump($adviceMcbid);exit;
    // 获取体检套餐适用的体检中心
    $centerDetail = S("centerDetailTuiJian","",array("prefix"=>$packageid, "temp"=>RUNTIME_PATH.'Temp/address')); // 获取体检中心缓存
    if(!$centerDetail){
            $url = $this->getBaseUrl() . "s/infoPepMc/getInfoPepMcList";
            foreach ($adviceMcbid as $key => $val) {
                $data = array(
                    'appKey' => $this->appKey(),
                    'invokeKey' => $this->invokeKey(),
                    'packageId' =>$packageid,
                    'mcbId'=>$val['mcbid'],
                    // 'pageSize' => 1000,
                );
                // dump($data);
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $return = curl_exec($ch);
                $getinfo = get_object_vars(json_decode($return));
                $result = get_object_vars(json_decode($getinfo['jsonResult']));
                $centerShow = (array)$result['dataList'];
                curl_close($ch);
                $centerShow ? $centerDetailList[] = $centerShow[0]: '';
            }
            S("centerDetailTuiJian",$centerDetailList,array("prefix"=>$packageid, "temp"=>RUNTIME_PATH.'Temp/address'));  // 写入缓存
            $centerDetail = S("centerDetailTuiJian","",array("prefix"=>$packageid, "temp"=>RUNTIME_PATH.'Temp/address'));  // 读取缓存
    }

        // dump($centerDetail);

    // 获取体检分支机构
    $cacheAddressList = S("AddressListTuiJian","",array("prefix"=>$packageid, "temp"=>RUNTIME_PATH.'Temp/address')); // 获取体检中心分支机构
    if(!$cacheAddressList){
        $url = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterBranchList";
        $addressList=array();
            foreach($centerDetail as $key=>$value){
                $data = array(
                    'appKey' => $this->appKey(),
                    'invokeKey' => $this->invokeKey(),
                    'mcbId' => $value->mcbId,
                    );
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $return = curl_exec($ch);
                curl_close($ch);
                $getinfo = get_object_vars(json_decode($return));
                $jsonResult=$getinfo['jsonResult'];
                $jsonResult=json_decode($jsonResult);
                $dataList=$jsonResult->dataList[0];

                $item["address"]=$dataList->address;
                $item['name']=$dataList->name;
                $item['mcbId']=$dataList->mcbId;
                $item['restDay']=$dataList->restDay;
                array_push($addressList,$item);
            }
            // dump($addressList);
            S("AddressListTuiJian",$addressList,array("prefix"=>$packageid, "temp"=>RUNTIME_PATH.'Temp/address')); // 分支机构写入缓存
            $cacheAddressList = S("AddressListTuiJian","",array("prefix"=>$packageid, "temp"=>RUNTIME_PATH.'Temp/address')); // 获取体检中心分支机构
            // echo '没有缓存,调用西门子接口';
    }
    // dump($cacheAddressList);

    // 存在推荐 返回数据
    if($cacheAddressList) return $cacheAddressList;
    return false;

}

    //地址列表（用于体检预约选择体检中心地址）
public function addressList()
{
     $url = $this->getBaseUrl() . "s/infoPepMc/getInfoPepMcList";
     $packageid=empty($_GET['packageid'])?"":$_GET['packageid'];
     $packageid=htmlspecialchars($packageid);
     $timeShijian = empty($_GET['timeShijian'])?"":$_GET['timeShijian'];
     $data = array(
        'appKey' => $this->appKey(),
        'invokeKey' => $this->invokeKey(),
        'packageId' =>$packageid ,
        'pageSize' => 1000,
        );
            // var_dump($data);exit();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     $return = curl_exec($ch);
            //var_dump($return);exit();
    // echo $return;exit;
     $getinfo = get_object_vars(json_decode($return));
     $result = get_object_vars(json_decode($getinfo['jsonResult']));
     $centerDetail = (array)$result['dataList'];
     curl_close($ch);
     // dump($centerDetail);exit;
        // print_r($centerDetail);exit;

     $url = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterBranchList";

    //这个页面加载太TM慢了，设置一下缓存
     $cacheAddressList = S("cacheAddressList","",array("prefix"=>$packageid, "temp"=>RUNTIME_PATH.'Temp/address'));
     if(!$cacheAddressList){
        //获取体检中心列表数据和百度地图数据
        $addressList=array();
        foreach($centerDetail as $key=>$value){
                    // var_dump($value);continue;
            $data = array(
                'appKey' => $this->appKey(),
                'invokeKey' => $this->invokeKey(),
                'mcbId' => $value->mcbId,
                );
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            $return = curl_exec($ch);
            curl_close($ch);
            $getinfo = get_object_vars(json_decode($return));
            $jsonResult=$getinfo['jsonResult'];
            $jsonResult=json_decode($jsonResult);
            $dataList=$jsonResult->dataList[0];
            $item["address"]=$dataList->address;
            $item['name']=$dataList->name;
            $item['mcbId']=$dataList->mcbId;
            $item['restDay']=$dataList->restDay;
            $item['tag'] = $dataList->tag;
            array_push($addressList,$item);
            //print_r($addressList);exit;
            $mapInfo[]=array($dataList->gpsLon,$dataList->gpsLat,$dataList->name.",".$dataList->mcbId,);
        }

        S("cacheAddressList",$addressList,array(
            "prefix"=>$packageid,
            // "expire"=>"30",
            "temp"=>RUNTIME_PATH.'temp/address')
        );
        $cacheAddressList = S("cacheAddressList","",array("prefix"=>$packageid, "temp"=>RUNTIME_PATH.'Temp/address'));
    }

    // dump($cacheAddressList);
    // exit;
    // dump($cacheAddressList);
    $tuijian = M('advice_cbid'); //推荐表
    $adviceMcbid = $tuijian -> field('mcbid') -> where('mcstate=2') -> select(); // 获取推荐的体检中心

    //  推荐的体检中心
    foreach ($adviceMcbid as $key => $val) {
        foreach ($cacheAddressList as $key1 => $val1) {
            if($adviceMcbid[$key]['mcbid']  == $cacheAddressList[$key1]['mcbId']){
                $tuiJianData[]= $cacheAddressList[$key1];
                unset($cacheAddressList[$key1]);  // 删除推荐的体检中心,避免数据重复
                break;
            }
        }
    }

    // dump($tuiJianData);
    // dump($cacheAddressList);
    // exit;
    // $tuijianAddressList= $this->adviceAddressList($packageid); // 推荐体检中心
    // $this->assign("addressListTuijian",$tuijianAddressList); // 推荐体检中心
    $this->assign("addressListTuijian",$tuiJianData);
    $this->assign("addressList",$cacheAddressList);
    $this->assign("timeShijian",$timeShijian);
    // dump($tuijianAddressList);
    // dump($cacheAddressList);exit;


    //获取体检中心选择栏列表
    // $url = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterList";
    // $data = array(
    //     'appKey' => $this->appKey(),
    //     'invokeKey' => $this->invokeKey(),
    //     'status' => 0,
    //     );
    // $ch = curl_init();
    // curl_setopt($ch, CURLOPT_URL, $url);
    // curl_setopt($ch, CURLOPT_POST, 1);
    // curl_setopt($ch, CURLOPT_HEADER, 0);
    // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    // $return = curl_exec($ch);
    // curl_close($ch);
    // $getinfo = get_object_vars(json_decode($return));
    // $result = json_decode($getinfo['jsonResult']);
    // $dataList = $result->dataList;
    // $this->assign("dataList", $dataList);


    $this->display();
}

   //体检中心地图
public function baiduMap()
{
    // 判断是http协议还是https协议
    // $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
    // dump($http_type);
    if((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')){
        // echo '我是https协议请求,我安全性高!!!';
    }else{
        // echo '我是http协议请求,我速度快';
    }

    // exit;

    $timeShijian = empty($_GET['timeShijian'])?"":$_GET['timeShijian'];

    $url = $this->getBaseUrl() . "s/infoPepMc/getInfoPepMcList";
    $packageid=empty($_GET['packageid'])?"":$_GET['packageid'];
    $data = array(
        'appKey' => $this->appKey(),
        'invokeKey' => $this->invokeKey(),
        'packageId' =>$packageid ,
        'pageSize' => 1000,
        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
        // var_dump($return);exit();

    $getinfo = get_object_vars(json_decode($return));
    $result = get_object_vars(json_decode($getinfo['jsonResult']));
    $centerDetail = (array)$result['dataList'];
    curl_close($ch);


    $url = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterBranchList";

    //这个页面加载太TM慢了，设置一下缓存
    $cacheMapInfo= S("cacheMapInfo","",array("prefix"=>$packageid."_", "temp"=>RUNTIME_PATH.'Temp/map'));
    // $cacheMapInfo=false;
    if(!$cacheMapInfo){
    //获取体检中心列表数据和百度地图数据
        $mapInfo=array();
        foreach($centerDetail as $key=>$value){
         $data = array(
            'appKey' => $this->appKey(),
            'invokeKey' => $this->invokeKey(),
            'mcbId' => $value->mcbId,
            );
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         $return = curl_exec($ch);
         curl_close($ch);
         $getinfo = get_object_vars(json_decode($return));
         $jsonResult=$getinfo['jsonResult'];
         $jsonResult=json_decode($jsonResult);
         $dataList=$jsonResult->dataList[0];
         // var_dump($dataList);exit();

         $mapInfo[]=array($dataList->gpsLon,$dataList->gpsLat,$dataList->name.",".$dataList->address.",".$dataList->mcbId,);
     }

     S("cacheMapInfo",$mapInfo,array(
        "prefix"=>$packageid."_",
        "expire"=>"3600",
        "temp"=>RUNTIME_PATH.'temp/map')
     );
     $cacheMapInfo = S("cacheMapInfo","",array("prefix"=>$packageid."_", "temp"=>RUNTIME_PATH.'Temp/map'));
 }

    //整理成百度地图API要求的数据格式
    foreach ($cacheMapInfo as $key => $value) {
        foreach ($value as $k => $v) {
            if ($k==2) {
                $ex=explode(",", $v);
                $v="<div class='address_content'><input type='hidden' class='mcbId' value='".$ex[2]."'/><label class='address_label'>".$ex[0]."</label><label class='address_detail'>".$ex[1]."</label><p style='display: block;padding: 3px 15px;margin: 6px auto;width: 120px;color: #000;border-radius: 5px;background:#fff;text-align:center;' class='address_button' onClick='getAddress();' >选择</p></div>";
                $value[$k]=urlencode($v);
            }

        }
        $mapInfo[$key] = $value;
    }

    $mapInfo=  urldecode ( json_encode ( $mapInfo ) );
    // var_dump($mapInfo);exit();
    $this->assign("mapInfo",$mapInfo);
    $this->assign("timeShijian",$timeShijian);
    $this->display();
}


    //机构详细信息
public function getMedicalCenterBranchList()
{
//        var_dump($_GET['packageId']);exit();
    $url = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterBranchList";
    $data = array(
        'appKey' => $this->appKey(),
        'invokeKey' => $this->invokeKey(),
        'packageId' => $_GET['packageId'],
        'mcId' => $_GET['mcId'],
        'mcbId' => $_POST['mcbId'],
        'name' => $_POST['name'],
        'country' => $_POST['country'],
        'province' => $_POST['province'],
        'city' => $_POST['city'],
        'address' => '',
        'telephone' => '',
        'description' => '',
        'gpsLat' => '',
        'gpsLon' => '',
        'baiduMapUrl' => '',
        'status' => $_POST['status'],
        'pageIndex' => $_POST['pageIndex'],
        'pageSize' => '10000',
        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);
    $getinfo = get_object_vars(json_decode($return));
    $result = json_decode($getinfo['jsonResult']);
    return $result->dataList;
    exit();
}

//体检中心列表
public function centerList()
{
    $url = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterBranchList";
    $data = array(
        'appKey' => $this->appKey(),
        'invokeKey' => $this->invokeKey(),
        'packageId' => $_GET['packageId'],
        'mcId' => $_GET['mcId'],
        'mcbId' => $_POST['mcbId'],
        'name' => $_POST['name'],
        'country' => $_POST['country'],
        'province' => $_POST['province'],
        'city' => $_POST['city'],
        'address' => '',
        'telephone' => '',
        'description' => '',
        'gpsLat' => '',
        'gpsLon' => '',
        'baiduMapUrl' => '',
        'status' => $_POST['status'],
        'pageIndex' => $_POST['pageIndex'],
        'pageSize' => '10000',
        );
    // var_dump($data);exit();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);
    $getinfo = get_object_vars(json_decode($return));
    $result = json_decode($getinfo['jsonResult']);
       // var_dump($result->dataList);exit();
    $result = $result->dataList;
    // $data=array();
    // foreach ($result as $key => $value) {
    //     $data[$key]['address']=$value->address;
    //     $data[$key]['name']=$value->name;
    //     $data[$key]['baiduMapUrl']=$value->baiduMapUrl;
    //     // var_dump($value);continue;

    //     $url_icon = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterList";
    //     $data_icon = array(
    //         'appKey' => $this->appKey(),
    //         'invokeKey' => $this->invokeKey(),
    //         'mcId' => $value->mcId,
    //         );

    //     $ch = curl_init();
    //     curl_setopt($ch, CURLOPT_URL, $url_icon);
    //     curl_setopt($ch, CURLOPT_POST, 1);
    //     curl_setopt($ch, CURLOPT_HEADER, 0);
    //     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //     curl_setopt($ch, CURLOPT_POSTFIELDS, $data_icon);
    //     $return_icon = curl_exec($ch);
    //     curl_close($ch);

    //     $getinfo_icon = get_object_vars(json_decode($return_icon));
    //     $result_icon = $getinfo_icon['jsonResult'];
    //     $result_icon=json_decode($result_icon);
    //     $result_icon=$result_icon->dataList;
    //     $result_icon=$result_icon[0]->icon;

    //     $data[$key]['icon']=$result_icon;
    // }



    $this->assign("data", $result);
    $this->display("centerlist");
}


/**
 *  某一个品牌的体检中心列表
 *
 */
public function centerBrandList()
{
    $url = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterBranchList";
    $data = array(
        'appKey' => $this->appKey(),
        'invokeKey' => $this->invokeKey(),
        'packageId' => $_GET['packageId'],
        'mcId' => $_GET['mcId'],
        'mcbId' => $_POST['mcbId'],
        'name' => $_POST['name'],
        'country' => $_POST['country'],
        'province' => $_POST['province'],
        'city' => $_POST['city'],
        'address' => '',
        'telephone' => '',
        'description' => '',
        'gpsLat' => '',
        'gpsLon' => '',
        'baiduMapUrl' => '',
        'status' => $_POST['status'],
        'pageIndex' => $_POST['pageIndex'],
        'pageSize' => '10000',
        );
    // var_dump($data);exit();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);
    $getinfo = get_object_vars(json_decode($return));
    $result = json_decode($getinfo['jsonResult']);
       // var_dump($result->dataList);exit();
    $result = $result->dataList;
    // $data=array();
    // foreach ($result as $key => $value) {
    //     $data[$key]['address']=$value->address;
    //     $data[$key]['name']=$value->name;
    //     $data[$key]['baiduMapUrl']=$value->baiduMapUrl;
    //     // var_dump($value);continue;

    //     $url_icon = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterList";
    //     $data_icon = array(
    //         'appKey' => $this->appKey(),
    //         'invokeKey' => $this->invokeKey(),
    //         'mcId' => $value->mcId,
    //         );

    //     $ch = curl_init();
    //     curl_setopt($ch, CURLOPT_URL, $url_icon);
    //     curl_setopt($ch, CURLOPT_POST, 1);
    //     curl_setopt($ch, CURLOPT_HEADER, 0);
    //     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //     curl_setopt($ch, CURLOPT_POSTFIELDS, $data_icon);
    //     $return_icon = curl_exec($ch);
    //     curl_close($ch);

    //     $getinfo_icon = get_object_vars(json_decode($return_icon));
    //     $result_icon = $getinfo_icon['jsonResult'];
    //     $result_icon=json_decode($result_icon);
    //     $result_icon=$result_icon->dataList;
    //     $result_icon=$result_icon[0]->icon;

    //     $data[$key]['icon']=$result_icon;
    // }



    $this->assign("data", $result);
    $this->display();
    // $this->display("centerBrandList");
}

    //体检机构
public function brandList()
{
    $url = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterList";
//        var_dump($url);exit();
    $data = array(
        'appKey' => $this->appKey(),
        'invokeKey' => $this->invokeKey(),
        'mcId' => $_POST['mcId'],
        'name' => $_POST['name'],
        'icon' => $_POST['icon'],
        'description' => $_POST['description'],
        'tags' => $_POST['tags'],
        'email' => $_POST['email'],
        'status' => 0,
        'pageIndex' => $_POST['pageIndex'],
        'pageSize' => $_POST['pageSize'],
        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
//        var_dump($return);exit();
    curl_close($ch);
    $getinfo = get_object_vars(json_decode($return));
    $result = json_decode($getinfo['jsonResult']);
    $dataList = $result->dataList;
  //     var_dump($dataList);exit();
    $this->assign("dataList", $dataList);
    $this->display("brandlist");
}
/**
 * 体检机构详情
 * 体检机构简介图片等信息
 */
public function brandDetail(){
    $wheres['mcId'] = $_GET['mcId'];
    $brandModel = M('brand_descr');
    $data = $brandModel ->where($wheres)-> find();

    if(!$data){
        echo '体检中心不存在'; exit;
    }
    // dump($data);

    $this->assign("data", $data);
    $this->display("branddetail");
}

public function indicatorList()
{
    // echo "hello";exit();
    $result = $this->getInfoExaminationItemList();
    foreach ($result['dataList'] as $key => $val) {
        $itemArr["$val->itemId"]['itemname'] = $val->name;
        $itemArr["$val->itemId"]['indicators'] = $this->getExaminationIndicatorList($val->itemId);
    }
//        print_r($itemArr);exit();
    $this->assign("itemArr", $itemArr);
    $this->display();
}

    //获取所有体检大项
public function getInfoExaminationItemList()
{
    $url = $this->getBaseUrl() . "s/infoExaminationItem/getInfoExaminationItemList";

    $data = array(
        'appKey' => $this->appKey(),
        'invokeKey' => $this->invokeKey(),
        'itemId' => $_POST['itemId'],
        'name' => $_POST['name'],
        'description' => $_POST['description'],
        'type' => $_POST['type'],
        'content' => $_POST['content'],
        'diagnosis' => $_POST['diagnosis'],
        'objective' => $_POST['objective'],
        'analysis' => $_POST['analysis'],
        'suggestion' => $_POST['suggestion'],
        'pageIndex' => $_POST['pageIndex'],
        'pageSize' => $_POST['pageSize'],
        );
    // var_dump($data);exit();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);

    $getinfo = get_object_vars(json_decode($return));
    $result = get_object_vars(json_decode($getinfo['jsonResult']));
    return $result;
}

    //获取所有体检小项
public function getExaminationIndicatorList($itemId)
{
//        var_dump($itemId);exit();

    $url = $this->getBaseUrl() . "s/examinationIndicator/getExaminationIndicatorList";
    $data = array(
        'appKey' => $this->appKey(),
        'invokeKey' => $this->invokeKey(),
        'itemId' => $itemId,

        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);
    $getinfo = get_object_vars(json_decode($return));
    $result = get_object_vars(json_decode($getinfo['jsonResult']));
//        var_dump($result);
    foreach ($result['dataList'] as $k => $v) {
        $indicator["$v->indicatorId"] = $v->name;
    }
    return $indicator;
}

    //短信验证
public function sendAuthcodeByPhoneNumber()
{
    $url = $this->getBaseUrl() . "s/sms/sendAuthcodeByPhoneNumber";
    $data = array(
        'appKey' => $_POST['appKey'],
        'invokeKey' => $_POST['invokeKey'],
        'phoneNumber' => $_POST['phoneNumber'],
        'templateNumber' => $_POST['templateNumber'],
        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);
    $getinfo = get_object_vars(json_decode($return));
    echo $return;
    exit();
}

    //注册
public function addAuthUser()
{
    $url = $this->getBaseUrl() . "s/userService/addAuthUser";
    $data = array(
        'appKey' => $_POST['appKey'],
        'invokeKey' => $_POST['invokeKey'],
        'userUid' => $_POST['userUid'],
        'userName' => $_POST['userName'],
        'userPassword' => $_POST['userPassword'],
        'userPreferredMobile' => $_POST['userPreferredMobile'],
        'validateUserMobile' => $_POST['validateUserMobile'],
        'userEmail' => $_POST['userEmail'],
        'validateUserEmail' => $_POST['validateUserEmail'],
        'userUsertypeDict' => $_POST['userUsertypeDict'],
        'addUserUid' => $_POST['addUserUid'],
        'userNickName' => $_POST['userNickName'],
        'userIdCardNumber' => $_POST['userIdCardNumber'],
        'userGenderDict' => $_POST['userGenderDict'],
        'userWedlockDict' => $_POST['userWedlockDict'],
        'userBirthday' => $_POST['userBirthday'],
        'userNationDict' => $_POST['userNationDict'],
        'userTelephoneNumber' => $_POST['userTelephoneNumber'],
        'userPostalAddress' => $_POST['userPostalAddress'],
        'userPostalCode' => $_POST['userPostalCode'],
        'userFaxNumber' => $_POST['userFaxNumber'],
        'userQq' => $_POST['userQq'],
        'userLocationProvince' => $_POST['userLocationProvince'],
        'userLocationCity' => $_POST['userLocationCity'],
        'userLocationArea' => $_POST['userLocationArea'],
        'userLocationStreet' => $_POST['userLocationStreet'],
        'userCompany' => $_POST['userCompany'],
        'userDepart' => $_POST['userDepart'],
        'userRemark' => $_POST['userRemark'],
        'userTag' => $_POST['userTag'],
        'userSignature' => $_POST['userSignature'],
        'userDescription' => $_POST['userDescription'],
        'userAccountEndtime' => $_POST['userAccountEndtime'],
        );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$return = curl_exec($ch);
curl_close($ch);
$getinfo = get_object_vars(json_decode($return));
echo $return;
exit();
}

    //登录
public function verifyLogin()
{
    $url = $this->getBaseUrl() . "s/auth/verifyLogin";
    $data = array(
        'appKey' => $_POST['appKey'],
        'invokeKey' => $_POST['invokeKey'],
        'salt' => $_POST['salt'],
        'loginName' => $_POST['loginName'],
        'loginPwd' => $_POST['loginPwd'],
        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);
    $getinfo = get_object_vars(json_decode($return));
    echo $return;
    exit();
}

    //根据Uid获取用户信息
public function getUserByUid()
{
    $url = $this->getBaseUrl() . "s/userService/getUserByUid";
    $data = array(
        'appKey' => $_POST['appKey'],
        'invokeKey' => $_POST['invokeKey'],
        'uid' => $_POST['uid'],
        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);
    $getinfo = get_object_vars(json_decode($return));
    echo $return;
    exit();
}

    //获取应用软件下载列表
public function getToDownloadSoftwareList()
{
    $url = $this->getBaseUrl() . "s/portal/getToDownloadSoftwareList";
    $data = array(
        'appKey' => $_POST['appKey'],
        'invokeKey' => $_POST['invokeKey'],
        'platformTypeDict' => $_POST['platformTypeDict'],
        'softwareName' => $_POST['softwareName'],
        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);
    echo $return;
    exit();
}

    //更新当前软件版本的下载次数

public function updateSoftwareDownloadNum()
{
    $url = $this->getBaseUrl() . "s/portal/updateSoftwareDownloadNum";
    $data = array(
        'appKey' => $_POST['appKey'],
        'invokeKey' => $_POST['invokeKey'],
        'softwareId' => $_POST['softwareId'],
        'currentVersion' => $_POST['currentVersion'],
        );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $return = curl_exec($ch);
    curl_close($ch);
    echo $return;
    exit();
}

    /*用户找回密码
     * 参数：invokeKey
     *  appKey
     *  uid
     *  userPwd
     */
    public function updateUserPwd()
    {
        $url = "http://jiankang.10086.cn/healthcare_service_restful/s/userService/updateUserPwd";
        $data = array(
            'invokeKey' => $_POST['invokeKey'],
            'appKey' => $_POST['appKey'],
            'uid' => $_POST['uid'],
            'userPwd' => $_POST['userPwd'],
            );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $return = curl_exec($ch);
        curl_close($ch);
        echo $return;
        exit();
    }

    /*
     * 郁香支付完成之后，同步信息到西门子
     * */
    public function purchaseInfoSync()
    {
        if (isset($_POST['out_trade_no'])) {
            $outTradeNo=$_POST['out_trade_no'];
            $purchase = M("Purchase");

            $itemPurchase =(object)$purchase->where("sn=$outTradeNo")->find();
            // var_dump($itemPurchase->uid);exit();
            $url = $this->getBaseUrl()."s/infoPhysicalExamination/getInfoPhysicalExaminationList";

            $data=array(
                'appKey'=>$this->appKey(),
                'invokeKey'=>$this->invokeKey(),
                'packageId'=>$itemPurchase->item_id,
                );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            $return = curl_exec($ch);
            $getInfo = get_object_vars(json_decode($return));
            $itemPackage=json_decode($getInfo['jsonResult']);
            $itemPackage=(object)$itemPackage->dataList[0];
            curl_close($ch);

            //获取platformproductid
            $url = $this->getOperationsBaseUrl()."s/product/getProductInformationByProductId";

            $data=array(
                'appKey'=>$this->appKey(),
                'invokeKey'=>$this->invokeKey(),
                // 'bossProductId'=>$itemPurchase->item_id,
                'platformProductId'=>$itemPurchase->item_id,
                );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            $return = curl_exec($ch);
            curl_close($ch);
           // var_dump($return);exit();
            $getinfo = get_object_vars(json_decode($return));
            $getinfo=json_decode($getinfo['jsonResult']);
            // var_dump($getinfo);exit();
            $platformProductId=$getinfo->data->platformProductId;





            $orderProductListArr=array(
                'amount'=>$itemPurchase->item_count,
                'originalPrice'=>$itemPackage->originalPrice*100,
                'originalTotalPrice'=>$itemPackage->originalPrice*$itemPurchase->item_count*100,
                'discount'=>(int)(($itemPackage->salePrice/$itemPackage->originalPrice)*10),
                'remark'=>$itemPackage->name,
                'platformProductId'=>$platformProductId,
                // 'platformProductId'=>"150070",           //测试
                'productName'=>$itemPackage->name,
                'serviceTypeDict'=>'21',
                // 'bossProductId'=>$itemPurchase->item_id,
                'startTime'=>$itemPurchase->add_date,
                'endTime'=>$itemPurchase->update_date,
                );
            // var_dump($orderProductListArr);exit();
            // $orderProductList=json_encode($orderProductListArr,JSON_UNESCAPED_UNICODE);

            //json字符串中文乱码解决
            foreach ( $orderProductListArr as $key => $value ) {
                $orderProductListArr[$key] = urlencode ( $value );
            }
            $orderProductList = urldecode ( json_encode ( $orderProductListArr ) );
            $orderProductList="[".$orderProductList."]";
            // echo $orderProductList;
           // dump($orderProductList);
           // exit();

            //向西门子平台同步信息，个人已支付订单接口
            $url = $this->getOperationsBaseUrl()."s/order/addPaidOrderInfoIndividualCustomer";
            // echo $url;exit();
            // dump($url);exit();
            $data = array(
                'appKey' => $this->appKey(),
                'invokeKey' => $this->invokeKey(),
                // 'bossOrderId' => $itemPurchase->item_id,                    //选填
                'productList' => $orderProductList,                    //必填
               'platformUserUid' => $itemPurchase->uid,                  //业务平台用户ID,必填
                'originalPrice' => $itemPackage->originalPrice*100,                   //原价  必填
                'finalPrice' => $itemPackage->salePrice*100,                      //订单实际金额    必填
                'paymentStatusDict' => '0',               //支付状态代码               必填 0-支付成功，1-支付失败
                'platformFlowNo' => $itemPurchase->sn,                  //全网唯一支付流水ID      必填
                'transactionTime' => $itemPurchase->add_date,                 //交易时间                必填
                'paymentChannelDict'=>"0"

                );
            // dump($data);exit;
            // print_r($data);exit();
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            $return = curl_exec($ch);
           // print_r($return);exit();
            curl_close($ch);

            echo $return;exit();
        }
    }
    public function getSuccessJump(){

        $uid = $_GET['uid'];
        // dump($uid);exit;
        //生成缓存
        $cachePackageList=S("cacheJianPackageList","",array("prefix"=>"packageList_","temp"=>RUNTIME_PATH.'Temp/recommend'));
        // dump($cachePackageList);//exit();
        if(!$cachePackageList){
            $url = $this->getBaseUrl() . "s/infoPhysicalExamination/getInfoPhysicalExaminationList";
            $data = array(
                'appKey' => $this->appKey(),
                'invokeKey' => $this->invokeKey(),
                'status' => 0,
                'pageSize' => 1000,
                );
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            $return = curl_exec($ch);
            curl_close($ch);

            $getinfo = get_object_vars(json_decode($return));
            $result = get_object_vars(json_decode($getinfo['jsonResult']));
            $dataList = (array)$result['dataList'];
            function mb_strs($str = '', $offset = 0, $len = 0){
                $len || ($len = strlen($str));
                preg_match_all('/./us', $str, $result);
                return implode('', array_slice($result[0], $offset, $len));
            }

            foreach ($dataList as $key => $value) {
                    $val = $value->name;
                    $va = mb_strs( $val, 0, 2);
                    if($va=='通用'  || $va=='美兆' || $va=='政企'){
                        unset($dataList[$key]);
                    }

            }
            // dump($dataList);
        //生成缓存
            $cacheState=S("cacheJianPackageList",$dataList,array("prefix"=>"packageList_","temp"=>RUNTIME_PATH.'Temp/recommend'));
            // dump($cacheState);
            //获取缓存
            $cachePackageList=S("cacheJianPackageList","",array("prefix"=>"packageList_","temp"=>RUNTIME_PATH.'Temp/recommend'));
        }
        // dump($cachePackageList);

// 展示4个
        $ii = 0;
        foreach ($cachePackageList as $key => $value) {
            if($ii>3){
                unset($cachePackageList[$key]);
            }
            $ii ++;
        }


        $this->assign("dataList", $cachePackageList);
        $this->assign("uid", $uid);
        $this->display();
    }

    /**
     *  百度地图加载方法，兼容http和https
     *  androidmap模板：为http版本，仅支持http请求；
     *  iosmap模板：为https版本，支持http与https请求。
     */
    public function compatbaidumap()
    {
        // 判断是http协议还是https协议
        // $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
        // dump($http_type);
        if((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')){
            // echo '我是https协议请求,我安全性高!!!';
            $httpsStatu = 'https';
        }else{
            // echo '我是http协议请求,我速度快';
            $httpsStatu = 'http';
        }


        $timeShijian = empty($_GET['timeShijian'])?"":$_GET['timeShijian'];

        $url = $this->getBaseUrl() . "s/infoPepMc/getInfoPepMcList";
        $packageid=empty($_GET['packageid'])?"":$_GET['packageid'];
        $data = array(
            'appKey' => $this->appKey(),
            'invokeKey' => $this->invokeKey(),
            'packageId' =>$packageid ,
            'pageSize' => 1000,
            );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $return = curl_exec($ch);
            // var_dump($return);exit();

        $getinfo = get_object_vars(json_decode($return));
        $result = get_object_vars(json_decode($getinfo['jsonResult']));
        $centerDetail = (array)$result['dataList'];
        curl_close($ch);


        $url = $this->getBaseUrl() . "s/medicalCenter/getMedicalCenterBranchList";

        //这个页面加载太TM慢了，设置一下缓存
        $cacheMapInfo= S("cacheMapInfo","",array("prefix"=>$packageid."_", "temp"=>RUNTIME_PATH.'Temp/map'));
        // $cacheMapInfo=false;
        if(!$cacheMapInfo){
            //获取体检中心列表数据和百度地图数据
            $mapInfo=array();
            foreach($centerDetail as $key=>$value){
                $data = array(
                   'appKey' => $this->appKey(),
                   'invokeKey' => $this->invokeKey(),
                   'mcbId' => $value->mcbId,
                   );
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $return = curl_exec($ch);
                curl_close($ch);
                $getinfo = get_object_vars(json_decode($return));
                $jsonResult=$getinfo['jsonResult'];
                $jsonResult=json_decode($jsonResult);
                $dataList=$jsonResult->dataList[0];
                // var_dump($dataList);exit();

                $mapInfo[]=array($dataList->gpsLon,$dataList->gpsLat,$dataList->name.",".$dataList->address.",".$dataList->mcbId.",".$dataList->restDay,'restDay'=>$dataList->restDay,);
            }

            S("cacheMapInfo",$mapInfo,array(
               "prefix"=>$packageid."_",
               "expire"=>"3600",
               "temp"=>RUNTIME_PATH.'temp/map')
            );
            $cacheMapInfo = S("cacheMapInfo","",array("prefix"=>$packageid."_", "temp"=>RUNTIME_PATH.'Temp/map'));
        }
       // dump($cacheMapInfo);exit;
        //整理成百度地图API要求的数据格式
        foreach ($cacheMapInfo as $key => $value) {
            foreach ($value as $k => $v) {
                if ($k==2) {
                    $ex=explode(",", $v);
                    $v="<div class='address_content'><input type='hidden' class='mcbId' value='".$ex[2]."'/><input type='hidden' class='restDay' value='".$value['restDay']."'/><label class='address_label'>".$ex[0]."</label><label class='address_detail'>".$ex[1]."</label><p style='display: block;padding: 3px 15px;margin: 6px auto;width: 120px;color: #000;border-radius: 5px;background:#00D305;text-align:center;' class='address_button' onClick='getAddress();' >选择</p></div>";
                    $value[$k]=urlencode($v);
                }

            }
            $mapInfo[$key] = $value;
        }

        $mapInfo=  urldecode ( json_encode ( $mapInfo ) );
        // var_dump($mapInfo);exit();
        $this->assign("mapInfo",$mapInfo);
        $this->assign("timeShijian",$timeShijian);
        //  androidmap为http版本，仅支持http请求；iosmap为https版本，支持http与https请求
        $httpsStatu == 'http' ? $this->display('androidmap') : $this->display('iosmap');
        // $this->display('iosmap');
    }





}
